/**
 *
 * @author ilya portnyagin iportnyagin@gmail.com
 */

package ru.portnyagin.helpdeskru.service;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import ru.portnyagin.helpdeskru.model.FileHD;
import ru.portnyagin.helpdeskru.model.FileHD_;
import ru.portnyagin.helpdeskru.model.Request;

@Stateless
public class FileHDService extends AbstractService<FileHD> {
    @PersistenceContext(unitName = "HelpDeskRuPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public FileHDService() {
        super(FileHD.class);
    }
    
    public List<FileHD> findByRequest(Request request) {
        
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery();
        Root<FileHD> z = cq.from(FileHD.class);
        cq.where(cb.equal(z.get(FileHD_.request), request));
        cq.select(z);
        return getEntityManager().createQuery(cq).getResultList();
        
    }
    
    
    
}

